from tortoise import fields
from tortoise.models import Model
from passlib.context import CryptContext

pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=50, unique=True)
    password = fields.CharField(max_length=128)
    is_superuser = fields.BooleanField(default=False)  # 假设你有这个字段来标识管理员
    balance = fields.DecimalField(max_digits=10, decimal_places=2, default=0.00)

    class PydanticMeta:
        exclude = ['password']

    # @classmethod
    # async def create_user(cls, username: str, password: str, is_superuser: bool = False, balance: float = 0.00):
    #     # hashed_password = pwd_context.hash(password)
    #     # print(hashed_password)
    #     """底层被二次加密了一次"""
    #     user = await cls.create(username=username, password=password, is_superuser=is_superuser, balance=balance)
    #     return user
    #
    # # def verify_password(self, plain_password: str) -> bool:
    # #     return pwd_context.verify(plain_password, self.password)
